#ifndef __SUBCTRL_H
#define __SUBCTRL_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "stm32f4xx_hal.h"

    typedef enum
    {
        kON,
        kOFF,
    } switch_state_t;

    typedef enum
    {
        kOK,
        kERR,
    } error_state_t;

    typedef enum
    {
        kModule1st,
        kModule2nd,
        kModule3rd,

        kModuleNum
    } pa_module_id_t;

    typedef struct
    {
        float current;
        float rf_wave;
        float temperature;
        const uint32_t *hardware;
    } pa_module_t;
    /**
     * @brief 未完成
     *
     */
    typedef struct
    {
        uint8_t init;
        uint8_t ip[4];
        /*待定*/
    } __ALIGNED(4) sub_control_flash_t;
    /**
     * @brief 分控制器结构体
     *
     */
    typedef struct
    {
        uint8_t frame_header;      // 帧头
        error_state_t state;       // 错误状态
        uint8_t init;              // 初始化标志
        uint8_t pa_en_bit;         // 模块使能位
        uint16_t soft_reset_count; // 软复位计数
        float current;             // 电流
        float att_val;             // 衰减器值
        float phase_val;           // 相位值
#define PA_MODULE_INSTALL_NUM 3
        pa_module_t pa[PA_MODULE_INSTALL_NUM]; // PA模块
        struct
        {
            float target;
            float forward;
            float reverse;
        } rf_power;                // 射频功率
        sub_control_flash_t flash; // flash数据
        union {
            uint8_t byte[4];
            uint16_t half[2];
            uint32_t word;
        } check;
    } sub_control_t;

#define SUBCTRL_BASE_ADDRESS 101
#define SUBCTRL_NUM 9

#define SUBCTRL_FRAME_HEADER 0x34
#define SUBCTRL_UNIVERSAL_ADDRESS 233
#define SUBCTRL_TYPE_QUERY 0x00
#define SUBCTRL_TYPE_POWER 0x01

    void SubCtrl_Query(uint8_t address);
    void SubCtrl_Power(uint8_t address, float power);

#ifdef __cplusplus
}
#endif

#endif